package com.linxianqin.springbootVue.controller.monitor;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.linxianqin.springbootVue.domain.convert.SysLogininforConvert;
import com.linxianqin.springbootVue.domain.convert.SysOperLogConvert;
import com.linxianqin.springbootVue.domain.dto.SysOperLogDTO;
import com.linxianqin.springbootVue.domain.entity.SysLogininfor;
import com.linxianqin.springbootVue.domain.entity.SysOperLog;
import com.linxianqin.springbootVue.domain.enums.BusinessType;
import com.linxianqin.springbootVue.domain.model.AjaxResult;
import com.linxianqin.springbootVue.domain.page.TableDataInfo;
import com.linxianqin.springbootVue.domain.query.operLogQuery;
import com.linxianqin.springbootVue.domain.vo.SysLogininforExcel;
import com.linxianqin.springbootVue.domain.vo.SysOperLogExcel;
import com.linxianqin.springbootVue.manage.annotation.SysLog;
import com.linxianqin.springbootVue.manage.core.BaseController;
import com.linxianqin.springbootVue.service.SysOperLogService;
import com.linxianqin.springbootVue.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lxq
 * @version 1.0
 * @description: 操作日志记录
 * @date 2020/12/15 17:08
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController {
    private final SysOperLogService operLogService;
    public SysOperlogController(SysOperLogService operLogService){
        this.operLogService=operLogService;
    }

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public TableDataInfo list(operLogQuery query)
    {
        //构建分页bean
        Page<SysOperLogDTO> page = buildPage();
        //查询分页数据
        Page<SysOperLogDTO> list = operLogService.selectOperLogPage(page,query);
        return getDataTable(list);
    }

//    @SysLog(title = "操作日志", businessType = BusinessType.EXPORT)
//    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
//    @GetMapping("/export")
//    public AjaxResult export()
//    {
//        //查询数据库，查询所有
//        List<SysOperLog> list = operLogService.list();
//        //构建Excel工具包
//        ExcelUtil<SysOperLogExcel> util = new ExcelUtil<>(SysOperLogExcel.class);
//        //转化实体
//        List<SysOperLogExcel> sysOperLogExcels = SysOperLogConvert.INSTANCE.entity2Excel(list);
//        //序号id
//        for (int i = 0; i < sysOperLogExcels.size(); i++) {
//            sysOperLogExcels.get(i).setIndex(i+1);
//        }
//        return util.exportExcel(sysOperLogExcels, "操作日志");
//    }

    @SysLog(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{operIds}")
    public AjaxResult remove(@PathVariable List<Long> operIds)
    {
        return toAjax(operLogService.removeByIds(operIds));
    }

    @SysLog(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        operLogService.cleanOperLog();
        return AjaxResult.success();
    }
}
